//
//  HomeMindDataView.m
//  Ginix
//
//  Created by 冯志强 on 2025/2/21.
//

#import "HomeMindDataView.h"
#import "HomeMindDataCell.h"

@interface HomeMindDataView()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView * listView;
@property (nonatomic,strong) NSArray * listArray;
@end

@implementation HomeMindDataView

-(void)setSubViewLayout{
    [super setSubViewLayout];
    
    self.titleLabel.text = @"需要关注的心理状态";

    
    [self addSubview:self.listView];
    [_listView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView.mas_bottom).offset(10 * FMScaleX);
        make.left.equalTo(self.bgview.mas_left).offset(19 * FMScaleX);
        make.right.equalTo(self.bgview.mas_right).offset(-18 * FMScaleX);
        make.bottom.equalTo(self.bgview.mas_bottom).offset(-10 * FMScaleX);
    }];
}

-(void)setInfoModel:(HomeQuickCheckModel *)infoModel{
    
    self.listArray = [infoModel.nameNum copy];
    [self.listView reloadData];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.listArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 38 * FMScaleX;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HomeMindDataCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HomeMindDataCell"];
    HomePsychologyModel * model = self.listArray[indexPath.row];
    if (model) {
        [cell setInfoModel:model];
    }
    return cell;
}


-(UITableView *)listView{
    
    if (!_listView) {
        _listView = [[UITableView alloc]init];
        _listView.delegate = self;
        _listView.dataSource = self;
        _listView.showsVerticalScrollIndicator = NO;
        _listView.showsHorizontalScrollIndicator = NO;
        _listView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _listView.backgroundColor = UIColor.clearColor;
        [_listView registerClass:[HomeMindDataCell class] forCellReuseIdentifier:@"HomeMindDataCell"];
    }
    return _listView;
}

-(NSArray *)listArray{
    
    if (!_listArray) {
        _listArray = [[NSArray alloc]init];
    }
    return _listArray;
}
@end
